import Vue from "vue";
import VueRouter from "vue-router";
import Home from "../views/Home.vue";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    name: "Home",
    component: Home
  },
  {
    path: "/about",
    name: "About",
    component: () => import("../views/About.vue"),
  },
  {
    path: "/privacy",
    name: "Privacy",
    component: () => import("../views/Privacy.vue"),
  },
  {
    path: "/explore",
    name: "Explore",
    component: () => import("../views/Explore.vue")
  },
  {
    path: "/link",
    name: "FollowLink",
    component: () => import("../views/FollowLink.vue")
  },
  {
    path: "/follow",
    name: "Follow",
    component: () => import("../views/Follow.vue")
  },
  {
    path: "/myarticle",
    name: "MyArticle",
    component: () => import("../views/MyArticle.vue")
  },
  {
    path: "/edit",
    name: "CreateArticle",
    component: () => import("../views/EditArticle.vue")
  },
  {
    path: "/search",
    name: "Search",
    component: () => import("../views/Search.vue")
  },
  {
    path: "/edit/:id",
    name: "EditArticle",
    props: true,
    component: () => import("../views/EditArticle.vue")
  },
  {
    path: "/article/:id",
    name: "Article",
    component: () => import("../views/Article.vue"),
    props: true
  },
  {
    path: "/creater/:name",
    name: "Creater",
    component: () => import("../views/Creater.vue"),
    props: true
  },
  {
    path: "/mycomment",
    name: "MyComment",
    component: () => import("../views/MyComment.vue")
  },
  {
    path: "/setting/account",
    name: "Setting",
    component: () => import("../views/Setting.vue"),
    beforeEnter: (to, from, next) => {
      if (localStorage.token) {
        next();
      } else {
        next("/explore");
      }
    }
  }
];

const router = new VueRouter({
  routes
});

export default router;
